function isUserScriptsAvailable() {
    try {
        // Property access which throws if developer mode is not enabled.
        chrome.userScripts;
        return true;
    } catch {
        // Not available.
        return false;
    }
}

if (isUserScriptsAvailable()) {
    chrome.userScripts.configureWorld(
        {
            csp: "script-src 'self'",
            messaging: true,
        },
        () => {},
    );

    chrome.userScripts.register(
        [
            {
                id: 'test',
                matches: ['*://*/*'],
                js: [{ code: 'alert("Hi!")' }],
                allFrames: true,
                runAt: 'document_start',
                world: 'USER_SCRIPT',
            },
        ],
        () => {},
    );
}
